open(BUFF,"snps_ill.txt");
while(<BUFF>)
{
	chomp($_);
	@a = split(" ",$_);
	$hash{$a[1]} ="";
}
open(BUFF,"final.dosage");
open(WRBUFF,">ill_10000_dosage_before");
open(WRBUFF1,">ill_10000_dosage_after");
while(<BUFF>)
{
        chomp($_);
	@a = split(" ",$_);
	if(exists($hash{$a[0]}))
	{
		if($a[2] eq "-")
		{
			$a[2] = $a[1];
		}
		$_ = join(" ",@a);
		$hash{$a[0]} = $_;
		print WRBUFF1 $hash{$a[0]}."\n";
	}
}
open(BUFF,"ILL_200samples.tped");
while(<BUFF>)
{
        chomp($_);
        @a = split(" ",$_);
	shift(@a);
	$snp = shift(@a);
	shift(@a);
	shift(@a);
	if(exists($hash{$snp}))
	{
		@b =split(" ",$hash{$snp});
		$tped_snp1 = $b[1];
		$tped_snp2 = $b[2];
		@mainar =();
		push(@mainar,$snp);
		push(@mainar,$tped_snp1);
		push(@mainar,$tped_snp2);
		for($g=0;$g<@a;$g++)
                {
                        $ssnp1 = $tp_array[$g];
                        $g++;
                        $ssnp2 = $tp_array[$g];
                        if($ssnp1 eq $tped_snp1 && $ssnp2  eq $tped_snp1)
                        {
                                push(@mainar,1);
                                push(@mainar,0);
                        }
                        elsif($ssnp1 eq $tped_snp2 && $ssnp2  eq $tped_snp2)
                        {
                                push(@mainar,0);
                                push(@mainar,0);
                        }
                        elsif($ssnp1 eq "0" && $ssnp2  eq "0")
                        {
                                push(@mainar,'-');
                                push(@mainar,'-');
                        }
                        else
                        {
                                push(@mainar,0);
                                push(@mainar,1);
                        }
                }
		$line = join(" ",@mainar);
		print WRBUFF $line."\n";		
	}
}

